

#import "MBProgressHUD+WJTools.h"
//#import "HQMTopWindow.h"

@implementation MBProgressHUD (WJTools)

#pragma mark 显示信息
+ (void)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view dissmissTime:(CGFloat)time
{
    
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    // 设置字体大小
    hud.label.font = [UIFont systemFontOfSize:16];
    // 设置内容
    hud.label.text = text;
    
    // 设置颜色
    hud.bezelView.color = [UIColor blackColor];
    hud.backgroundView.backgroundColor = [UIColor blackColor];
    hud.backgroundView.alpha = 0.3;
    hud.backgroundView.hidden = NO;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;

    // 设置图片
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    // 再设置模式
    hud.mode = MBProgressHUDModeCustomView;
    
    // MBProgressHUDModeCustomView 此模式下设置title颜色
    hud.contentColor = [UIColor whiteColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (time != 0) {
        // 秒之后再消失
        [hud hideAnimated:YES afterDelay:time];
    }
}

# pragma mark 显示等待信息
+ (void)showWaitingInfoWithTitle:(NSString *)title view:(UIView*)view dissmissTime:(CGFloat)time{
//    UIView * view = [[UIApplication sharedApplication].windows lastObject];
     if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    // 设置字体大小
    hud.label.font = [UIFont systemFontOfSize:16];
    // 设置内容
    hud.label.text = title;
    
    // 设置颜色
    hud.bezelView.color = [UIColor blackColor];
    hud.backgroundView.backgroundColor = [UIColor blackColor];
    hud.backgroundView.alpha = 0.3;
    hud.backgroundView.hidden = NO;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    // 再设置模式
    hud.mode = MBProgressHUDModeIndeterminate;
    
    // MBProgressHUDModeCustomView 此模式下设置title颜色
    hud.contentColor = [UIColor whiteColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (time != 0) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [hud hideAnimated:YES];
            //        [self showSuccess:@"登录成功"];
        });
        // time秒之后再消失
        //        [hud hideAnimated:YES afterDelay:time];
    }
}
# pragma mark 显示等待信息
+ (void)showWaitingInfoWithTitle:(NSString *)title dissmissTime:(CGFloat)time{
    UIView * view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    
    // 设置字体大小
    hud.label.font = [UIFont systemFontOfSize:16];
    // 设置内容
    hud.label.text = title;
    
    // 设置颜色
    hud.bezelView.color = [UIColor blackColor];
    hud.backgroundView.backgroundColor = [UIColor blackColor];
    hud.backgroundView.alpha = 0.3;
    hud.backgroundView.hidden = NO;
    hud.backgroundView.style = MBProgressHUDBackgroundStyleSolidColor;
    
    // 再设置模式
    hud.mode = MBProgressHUDModeIndeterminate;
    
    // MBProgressHUDModeCustomView 此模式下设置title颜色
    hud.contentColor = [UIColor whiteColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (time != 0) {
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(time * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [hud hideAnimated:YES];
            //        [self showSuccess:@"登录成功"];
        });
        // time秒之后再消失
//        [hud hideAnimated:YES afterDelay:time];
    }
}

#pragma mark 显示错误信息
+ (void)showError:(NSString *)error toView:(UIView *)view dissmissTime:(CGFloat)time{
    [self show:error icon:@"error.png" view:view dissmissTime:time];
}

#pragma mark 显示成功信息
+ (void)showSuccess:(NSString *)success toView:(UIView *)view dissmissTime:(CGFloat)time{
    [self show:success icon:@"success.png" view:view dissmissTime:time];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view dissmissTime:(CGFloat)time{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
    
    // 设置模式
    hud.mode = MBProgressHUDModeIndeterminate;

    // 颜色
    hud.bezelView.color = [UIColor blackColor];
    hud.contentColor = [UIColor whiteColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (time != 0) {
        // time秒之后再消失
        [hud hideAnimated:YES afterDelay:time];
    }
    return hud;
}

+ (void)showSuccess:(NSString *)success
{
    [self showSuccess:success toView:nil dissmissTime:0.75f];
}

+ (void)showError:(NSString *)error
{
    [self showError:error toView:nil dissmissTime:0.75f];
}

+ (MBProgressHUD *)showMessage:(NSString *)message dissmissTime:(CGFloat)time
{
    return [self showMessage:message toView:nil dissmissTime:time];
}

+ (MBProgressHUD *)showOnlyTextMessage:(NSString *)message dissmissTime:(CGFloat)time{
    return [self showOnlyTextMessage:message toView:nil dissmissTime:time];
}

#pragma mark 显示一些信息
+ (MBProgressHUD *)showOnlyTextMessage:(NSString *)message toView:(UIView *)view dissmissTime:(CGFloat)time{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    // 快速显示一个提示信息initWithView
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.mode  = MBProgressHUDModeText;
    
    // 颜色
    hud.bezelView.color = [UIColor blackColor];
    hud.contentColor = [UIColor whiteColor];
    
    // 隐藏时候从父控件中移除
    hud.removeFromSuperViewOnHide = YES;
    if (time != 0) {
        // time秒之后再消失
        [hud hideAnimated:YES afterDelay:time];
    }
    return hud;
}


+ (void)hideHUDForView:(UIView *)view
{
    if (view == nil) view = [[UIApplication sharedApplication].windows lastObject];
    [self hideHUDForView:view animated:YES];
}

+ (void)hideHUD
{
    [self hideHUDForView:nil];
}

@end
